#include "globalsettings.h"
#include "ui_globalsettings.h"
#include "globalconfig.h"

GlobalSettings::GlobalSettings(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::GlobalSettings)
{
    ui->setupUi(this);
    ui->txtInt->setText(QString::number(gConf.interval));
    ui->txtTask->setText(QString::number(gConf.maxTask));
    connect(this, SIGNAL(accepted()), this, SLOT(updateData()));
}

GlobalSettings::~GlobalSettings()
{
    delete ui;
}

void GlobalSettings::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void GlobalSettings::updateData()
{
    int t = 0;
    t = ui->txtInt->text().toInt();
    if(t > 1000)
        gConf.interval = t;
    t = ui->txtTask->text().toInt();
    if(t > 0)
        gConf.maxTask = t;
    gConf.save();
}
